import './everyDayKind.scss'
import CONSTANT from '@/common/constants.js'
import http from '@/common/http.js'
import Checklist from 'vux/src/components/checklist/index.vue'
import XSwitch from 'vux/src/components/x-switch/index.vue'
import Group from 'vux/src/components/group/index.vue'
import Picker from 'vux/src/components/picker/index.vue'
import Popup from 'vux/src/components/popup/index.vue'
import Cell from 'vux/src/components/cell/index.vue'
import TransferDom from 'vux/src/directives/transfer-dom/index'

let hours = []
let minutes = []
for (var i = 1; i <= 24; i++) {
  hours.push({
    name: i + '时',
    value: i + ''
  })
}
for (var m = 0; m <= 59; m++) {
  var ms = m
  if (ms < 10) {
    ms = '0' + ms
  }
  minutes.push({
    name: ms + '分',
    value: ms + ''
  })
}
let userId = window.sessionStorage.getItem('userId')
export default {
  name: 'findrank',
  directives: {
    TransferDom
  },
  components: { Checklist, XSwitch, Group, Picker, Popup, Cell },
  data () {
    return {
      labelPosition: 'left',
      commonList: [ '周一', '周二', '周三', '周四', '周五', '周六', '周日' ],
      commonList1: [ '每天' ],
      checklist01: [],
      checklist02: [],
      stringValue: false,
      ifOpen: '关闭',
      years1: [hours, minutes],
      time04: ['12', '00'],
      showgr: false,
      thetime: '12:00',
      disabled01: false,
      disabled02: false
    }
  },
  mounted () {
    // MEMORANDUM_SAVE
    this.obtain()
  },
  methods: {
    obtain () {
      http.post(CONSTANT.MEMORANDUM_VIEW, {user_id: userId}, (res) => {
        console.log(res)
        if (res.code == 200) {
          this.time04 = [res.obj.hour, res.obj.minute]
          this.thetime = res.obj.hour + ':' + res.obj.minute
          if (res.obj.status == 1) {
            this.stringValue = true
          } else {
            this.stringValue = false
          }
          if (res.obj.cycle == '每天') {
            this.checklist01 = res.obj.cycle
          } else {
            this.checklist02 = res.obj.cycle
          }
        }
      })
    },
    pramise () {
      // 保存按钮
      var status = ''
      var hour = ''
      var minute = ''
      var cycle = ''
      hour = this.time04[0]
      minute = this.time04[1]
      if (this.checklist01[0] == '每天') {
        cycle = this.checklist01
      } else {
        cycle = this.checklist02
      }
      if (this.stringValue == false) {
        status = 0
      } else {
        status = 1
      }
      http.post(CONSTANT.MEMORANDUM_SAVE, {user_id: userId, cycle: cycle, status: status, hour: hour, minute: minute}, (res) => {
        console.log(res)
        if (res.errmsg == '保存成功') {
          alert('保存成功！')
        }
        if (res.errmsg == '修改成功') {
          alert('修改成功')
        }
      })
    },
    changeall (val) {
      // 选择每天
      console.log(val)
      if (val[0] == '每天') {
        this.disabled02 = true
        this.checklist02 = []
      } else {
        this.disabled02 = false
      }
    },
    switchChange (val) {
      // 开启关闭按钮
      console.log(val)
      if (val == false) {
        this.ifOpen = '关闭'
      } else {
        this.ifOpen = '开启'
      }
    },
    timeDate () {
      this.showgr = true
    },
    change (val, label) {
      // 选择周期
      console.log('change', val)
    },
    changepicker (value) {
      console.log(value)
    },
    closegr () {
      this.showgr = false
      this.thetime = this.time04[0] + ':' + this.time04[1]
    }
  }
}
